<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<meta name="renderer" content="webkit|ie-comp|ie-stand" />
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
<title>班级首页</title>
<%@ include file="/common/commonLib.jsp"%>
<link rel="stylesheet" type="text/css" href="<c:url value='/css/courseLesson-stu.css'/>"/>
<link rel="stylesheet" type="text/css" href="<c:url value='/css/common-main.css'/>"/>
<script src="<c:url value='/js/courseLesson.js'/>" type="text/javascript" charset="utf-8"></script>
</head>
<body>
	<%@include file="/common/header.jsp"%>
	<%@include file="classHeader.jsp"%>
	<div class="container-fluid main">		
		<div class="row">
			<!--课堂、任务、资源、成绩、评论、答疑-->
			<div class="col-xs-12 col-sm-12 col-md-9">
				<div class="row">					
					<!--课堂、任务、资源、成绩、评论、答疑----内容-->
					<div class="col-md-12">
						<%@include file="classNav.jsp"%>
						<div class="stu-course-info-con">
							<!--课堂列表-->
							<div class="col-md-12 col-xs-12">
								
								<div class="theory-and-lab">
									<div class="theory-lab-title">
										<ul>
											<li class="get-theory">理论课</li>
											<li class="get-lab">实验课</li>
										</ul>
									</div>
									<!--理论课课堂列表-->
									<div class="class-list">
										<div>
											<ul class="theory-list">
												
											</ul>
										</div>
										<!--实验课课堂列表-->
										<div>
											<ul class="lab-list">
											
											</ul>
										</div>
										<div class="page-content" id="lessonPage">
											<nav class="pagination" role="navigation">
												<a class="last-page" href="#">
													<i class="fa fa-angle-left"></i>
												</a>
												<span class="page-number">......</span>
												<a class="next-page" href="#">
													<i class="fa fa-angle-right"></i>
												</a>
											</nav>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
			<!--教师、助教信息，课程简介-->
			<div class="col-xs-12 col-md-3">
				<%@include file="classRight.jsp"%>
			</div>
		</div>
	</div>
	<%@include file="/common/footer.jsp"%>
</body>
<script>
var data=${data};
var lessonType ;
$(document).ready(function(){
	if (data.status != "success"){
		alert(data.message);
		return;
	}
	$("#lesson").css("color","#00b43c");
	lessonType="THEORY";
	initClassView(data.data.classView);
	initLesson(data.data);
});
var initLesson = function(data){
	var labList=$(".lab-list");
	var theoryList=$(".theory-list");
	labList.empty();
	theoryList.empty();
	var lessons=data.list;
	var flagL = 0, flagT = 0;
	
	for(var i=0;i<lessons.length;i++){
		var s="<a href=\"<c:url value='/lessonTaskView/stuView?lessonId="+lessons[i].id+"'/>\"><li title=\""+lessons[i].beginDate+"-"+lessons[i].endDate+"\">"+lessons[i].beginDate+"--"+lessons[i].endDate;
		if(lessons[i].status=="NOTSTART"){
			s+="<em class=\"classType\">未开始</em>";
		}else if(lessons[i].status=="INPROGRESS"){
			s+="<em class=\"classType\">进行中</em>";
		}else{
			s+="<em class=\"classType\">已结束</em>";
		}
		s+="</li></a>";
		if(lessons[i].type == "THEORY") {
			theoryList.append(s);
			flagT += 1;
		} else {
			labList.append(s);
			flagL += 1;
		}
	};
	if(flagT == 0){
		var s="<li>暂无课程</li>";
		theoryList.append(s);
	}
	if(flagL == 0){
		var s="<li>暂无课程</li>";
		labList.append(s);
	}
	
	initPages(data.pageNo,data.allpages);
}

var getLesson = function(type,page){
	var json={
		search:{
			classId:data.data.classView.classId,
			type:type
		},
		pageNo:page
	};
	$.get("<c:url value='/lesson/ajaxListData'/>",{
		data : JSON.stringify(json)
	},function(data) {
		lessonType=type;
		initLesson(data.data);
	});
}

var initPages = function(pageNo,allpages){
	
	 var lastPageObj=$("#lessonPage .last-page");
		var nextPageObj=$("#lessonPage .next-page");
		var pageNumberObj=$("#lessonPage .page-number");
		var lastPage=pageNo-1;
		if(lastPage<=0){//设置disableed
			lastPage=1;
		}else{
			 $("#lessonPage .last-page").bind("click",{pageNo:lastPage},getPage);
		};
		var nextPage = pageNo+1;
		if(nextPage>allpages){
			nextPage=allpages;
		}else{
			 $("#lessonPage .next-page").bind("click",{pageNo:nextPage}, getPage);
		}
		
		if(allpages <= 1){
			$("#lessonPage").hide();
		}else{
			pageNumberObj.text("第"+pageNo+"页/共"+allpages+"页");
		}
		//pageNumberObj.text("第"+pageNo+"页/共"+allpages+"页");
}
var getPage = function(event){
	var pageNo=event.data.pageNo;
	getLesson(lessonType,pageNo);
}
</script>
</html>